#!/bin/bash
# 代码质量检查脚本

echo "🔍 开始代码质量检查..."

# 创建报告目录
mkdir -p reports

# 1. Pylint检查
echo "📋 运行Pylint检查..."
pylint src/ --output-format=json > reports/pylint_report.json 2>/dev/null || true
pylint src/ --output-format=text > reports/pylint_report.txt 2>/dev/null || true

# 2. Flake8检查
echo "🔧 运行Flake8检查..."
flake8 src/ --output-file=reports/flake8_report.txt || true

# 3. 代码复杂度检查
echo "📊 运行代码复杂度检查..."
radon cc src/ --json > reports/complexity_report.json || true
radon cc src/ > reports/complexity_report.txt || true

# 4. 安全检查
echo "🔒 运行安全检查..."
bandit -r src/ -f json -o reports/security_report.json || true
bandit -r src/ -f txt -o reports/security_report.txt || true

# 5. 测试覆盖率
echo "🧪 运行测试覆盖率检查..."
coverage run -m pytest tests/ || true
coverage report > reports/coverage_report.txt || true
coverage html -d reports/htmlcov || true

echo "✅ 代码质量检查完成！报告保存在 reports/ 目录"
echo "📊 主要指标："
echo "   - Pylint评分: $(grep 'Your code has been rated' reports/pylint_report.txt | tail -1 || echo '待检查')"
echo "   - 测试覆盖率: $(grep 'TOTAL' reports/coverage_report.txt | awk '{print $4}' || echo '待检查')"

